/* eslint-disable import/prefer-default-export */
import React from 'react';
// import { history } from 'umi';
import { Form, DatePicker, Input } from 'antd';

import { getApplyjob } from '@/services/components/userform';
import { SearchInput, SelectForm } from '@/components/UserForm';
import AdvancedSearch from '@/components/AdvancedSearch';
import TreeSelectPro from '@/components/TreeSelectPro/TreeSelectPro';
import useTreeSelectData from '@/hooks/useTreeSelectData';
import { getCandidateFilterName } from '@/services/myRecruit/candidate';

const { RangePicker } = DatePicker;
const CandidateSearchForm = ({
    collapsed,
    form,
    submit,
    query,
    companyId, // 登陆人公司id
    route,
    candileaderShow = false // 控制是否显示招聘负责人
}) => {
    // mine: 我的候选人  company: 候选人管理
    const { path } = route;
    const [companyTreeData, companyTreeLoading] = useTreeSelectData('company');
    let typeJump = '';
    if (path === '/office/personnelManagement/recruit/candidate') {
        typeJump = 'company';
    } else if (path === '/personal/portal/recruit/candidate') {
        typeJump = 'mine';
    } else {
        throw new Error('未找到路径！请检查');
    }
    const { getFieldDecorator } = form;
    return (
        <AdvancedSearch
            form={form}
            onSubmit={() => submit({ eType: 'submit' })}
            onReset={() => submit({ eType: 'reset' })}
            expand={!collapsed}
        >
            <Form.Item label="姓名">
                {getFieldDecorator('candidateName', {
                    initialValue: ''
                })(<Input placeholder="请输入候选人姓名" allowClear />)}
            </Form.Item>
            <Form.Item label="应聘职位">
                {getFieldDecorator('recruitCode', {
                    initialValue: undefined,
                    rules: []
                })(
                    <SelectForm
                        params={{ companyId }}
                        // params={{ useCompanyId: '101' }}
                        requireParam={['companyId ']}
                        getData={params =>
                            getApplyjob(params).then(res => {
                                if (res && res.code === 10000 && res.data) {
                                    return res.data || [];
                                }
                                return [];
                            })
                        }
                        fieldsName={{
                            selectValue: 'recruitCode',
                            selectTitle: 'recruitName'
                        }}
                        // onChange={this.companyChange}
                        selectProps={{
                            placeholder: '请选择应聘职位',
                            allowClear: true,
                            dropdownMatchSelectWidth: false
                        }}
                    />
                )}
            </Form.Item>
            {/* <Form.Item label="公司">
                {getFieldDecorator('companyId', {
                    initialValue: undefined
                })(
                    <TreeSelectForm
                        params={{ companyId }}
                        requireParam={['companyId ']}
                        getData={params =>
                            getCompanyTree(params).then(res => {
                                if (res && res.code === 10000 && res.data) {
                                    return res.data || [];
                                }
                                return [];
                            })
                        }
                        fieldsName={{
                            value: 'id',
                            title: 'companyName'
                        }}
                        // onChange={this.companyChange}
                        Props={{
                            placeholder: '请选择所属公司',
                            showArrow: true
                        }}
                    />
                )}
            </Form.Item> */}
            <Form.Item label="公司">
                {form.getFieldDecorator('companyId', { initialValue: undefined })(
                    <TreeSelectPro
                        loading={companyTreeLoading}
                        showSearch
                        treeDefaultExpandAll
                        treeData={companyTreeData}
                        placeholder="请选择所属公司"
                        allowClear
                    />
                )}
            </Form.Item>
            <Form.Item label="添加候选时间">
                {getFieldDecorator('addtime', {
                    initialValue: typeof query.addtime !== 'undefined' ? query.addtime : undefined
                })(<RangePicker format="YYYY-MM-DD" />)}
            </Form.Item>
            {typeJump === 'company' || candileaderShow ? (
                <Form.Item label="招聘负责人">
                    {getFieldDecorator('candidateLeaderId', {
                        initialValue: undefined
                    })(
                        <SearchInput
                            params={{
                                companyId,
                                roleName: '招聘负责人'
                            }}
                            requireParam={['companyId', 'roleName']}
                            getData={params =>
                                getCandidateFilterName(params).then(res => {
                                    if (res && res.code === 10000) {
                                        return res.data || [];
                                    }
                                    return [];
                                })
                            }
                            selectProps={{
                                placeholder: '请输入招聘负责人姓名',
                                allowClear: true
                            }}
                            fieldsName={{
                                value: 'id',
                                title: 'employeeName',
                                extraParams: 'employeeName',
                                isBuLu: true
                            }}
                            // onChange={this.handleSelect}
                        />
                    )}
                </Form.Item>
            ) : null}
        </AdvancedSearch>
    );
};

export default CandidateSearchForm;
